(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

module type OrderedType = Map.OrderedType
  
module type S =
sig
  type elt
  type 'a t
    
  val empty : 'a t
  val is_empty : 'a t -> bool
  val prefix : 'a t -> elt -> 'a t
  val root_value : 'a t -> 'a option
  val depth : 'a t -> int
  val find_array : elt array -> 'a t -> 'a
  val mem_array : elt array -> 'a t -> bool
  val find_list : elt list -> 'a t -> 'a
  val mem_list : elt list -> 'a t -> bool
  val generic_lookup :
    (('a t -> elt -> 'a t) -> 'a t -> 'b -> 'a t) ->
    'b -> 'a t -> 'a option
  val generic_lookup_prefix :
    (((('a t) * ('a t)) -> elt -> (('a t) * ('a t))) ->
       (('a t) * ('a t)) -> 'b -> (('a t) * ('a t)))
    -> 'b -> 'a t -> 'a option
  val lookup_array : elt array -> 'a t -> 'a option
  val lookup_list : elt list -> 'a t -> 'a option
  val lookup_prefix_array : elt array -> 'a t -> 'a option
  val lookup_prefix_list : elt list -> 'a t -> 'a option
  val add_array : elt array -> 'a -> 'a t -> 'a t
  val remove_array : elt array -> 'a t -> 'a t
  val add_list : elt list -> 'a -> 'a t -> 'a t
  val remove_list : elt list -> 'a t -> 'a t
  val merge : 'a t -> 'a t -> 'a t
  val map : ('a -> 'b) -> 'a t -> 'b t
  val mapi : (elt array -> 'a -> 'b) -> 'a t -> 'b t
  val iter : (elt array -> 'a -> unit) -> 'a t -> unit
  val fold : (elt array -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
end

module Make (Ord : OrderedType) : S with type elt = Ord.t
